package com.hp.ssm.controller;


import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;



import com.hp.ssm.entity.Hospital;
import com.hp.ssm.service.HospitalService;
import com.hp.ssm.util.ResultJson;
import com.hp.ssm.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;



@Controller
@RequestMapping("/hospital")
public class HospitalController {
    @Autowired
    private HospitalService hspitalService;

    //可以操作的列表
    @RequestMapping("/findAll")
    @ResponseBody
    public void findAll(Hospital hospital,Integer page, Integer limit,HttpServletResponse resp) {
        System.out.println(page + "你好我是page and  limit  " + limit + hospital);
        List<Hospital> list = hspitalService.findAll(hospital,page,limit);
        PageInfo<Hospital> userPageInfo = new PageInfo<Hospital>(list);
        System.out.println(list);
        System.out.println(list.size());
        Utils.returnJson(ResultJson.success(userPageInfo), resp);
    }
    /*
    * 添加
    * */
    @ResponseBody
    @RequestMapping("/add")
    public void add(Hospital hospital, HttpServletResponse resp){
        System.out.println(hospital);
        int i = hspitalService.add(hospital);
        ResultJson success = ResultJson.success(i);
        Utils.returnJson(success, resp);
    }
   /*
   * 查询单个
   * */
    @ResponseBody
    @RequestMapping("/findById")
    public ModelAndView findById(Integer hid, HttpServletRequest req, HttpServletResponse resp) {
        Hospital h = hspitalService.findById(hid);
        ResultJson success = ResultJson.success(h);
        Utils.returnJson(success, resp);
        return null;
    }
    //修改
    @ResponseBody
    @RequestMapping("/update")
    public void update(Hospital hospital, HttpServletResponse resp){
        int i = hspitalService.update(hospital);
        ResultJson success = ResultJson.success(i);
        Utils.returnJson(success, resp);
    }
    //修改状态
    @ResponseBody
    @RequestMapping("/delete")
    public void delete(Integer hid, HttpServletResponse resp){
        int i = hspitalService.delete(hid);
        ResultJson success = ResultJson.success(i);
        Utils.returnJson(success, resp);
    }
    //假删除的列表
    @RequestMapping("/deletefindAll")
    @ResponseBody
    public void findAll2(Hospital hospital,HttpServletResponse resp, Integer page, Integer limit) {
        System.out.println(page + "你好我是page and  limit  " + limit + hospital);
        List<Hospital> list = hspitalService.deletefindAll(hospital,page,limit);
        PageInfo<Hospital> userPageInfo = new PageInfo<Hospital>(list);
        System.out.println(list);
        System.out.println(list.size());
        Utils.returnJson(ResultJson.success(userPageInfo), resp);
    }
    //恢复状态
    @ResponseBody
    @RequestMapping("/recover")
    public void recover(Hospital hospital, HttpServletResponse resp){
        int i = hspitalService.recover(hospital);
        ResultJson success = ResultJson.success(i);
        Utils.returnJson(success, resp);
    }
}
